#include "selectgamepanel.h"

const int SelectGamePanel::ID_PLAYER_VERSUS_AI=110;
const int SelectGamePanel::ID_AI_VERSUS_AI=111;
const int SelectGamePanel::ID_BACK_TO_MENU_PANEL=112;
const int SelectGamePanel::ID_START_GAME=113;


SelectGamePanel::SelectGamePanel(wxFrame*frame,int id) : wxPanel(frame,id,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL,wxT("Menu Panel"))
{
    this->isgamesetted=false;
    wxColour col1;
    col1.Set(wxT("#99ff33"));

    wxImage::AddHandler(new wxPNGHandler);
    bmppvsai = new wxBitmap(wxT("source\\flower.png"),wxBITMAP_TYPE_PNG);
    bmpaivsai = new wxBitmap(wxT("source\\bgr2.png"),wxBITMAP_TYPE_PNG);

    leftpanel = new wxPanel(this,wxID_ANY,wxDefaultPosition,wxSize(324,700));

//    parentpanelpvsai = new wxPanel(leftpanel,wxID_ANY,wxDefaultPosition,wxSize(300,275));
//    parentpanelpvsai->SetBackgroundColour(col1);
//    childpanelpvsai = new wxPanel(parentpanelpvsai,wxID_ANY,wxDefaultPosition,wxDefaultSize);
    pvsai = new wxBitmapButton(leftpanel,ID_PLAYER_VERSUS_AI,wxBitmap(wxT("source\\exit2bigger.png"),wxBITMAP_TYPE_PNG));
//    wxBoxSizer *vbox1 = new wxBoxSizer(wxVERTICAL);
//    vbox1->Add(childpanelpvsai,0,wxEXPAND|wxALL,20);
//    parentpanelpvsai->SetSizer(vbox1);

//    parentpanelaivsai = new wxPanel(leftpanel,wxID_ANY,wxDefaultPosition,wxSize(300,550));
//    parentpanelaivsai->SetBackgroundColour(col1);
//    childpanelaivsai = new wxPanel(parentpanelaivsai,wxID_ANY,wxDefaultPosition,wxDefaultSize);
    aivsai = new wxBitmapButton(leftpanel,ID_AI_VERSUS_AI,wxBitmap(wxT("source\\exit2bigger.png"),wxBITMAP_TYPE_PNG));
//    wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL);
//    vbox2->Add(childpanelaivsai,0,wxEXPAND|wxALL,20);
//    parentpanelaivsai->SetSizer(vbox2);

//    parentpanelback = new wxPanel(leftpanel,wxID_ANY,wxDefaultPosition,wxSize(300,700));
//    parentpanelback->SetBackgroundColour(col1);
//    childpanelback = new wxPanel(parentpanelback,wxID_ANY,wxDefaultPosition,wxDefaultSize);
    backtomenupanel = new wxBitmapButton(leftpanel,ID_BACK_TO_MENU_PANEL,wxBitmap(wxT("source\\exit2.png"),wxBITMAP_TYPE_PNG));
//    wxBoxSizer *vbox3 = new wxBoxSizer(wxVERTICAL);
//    vbox3->Add(childpanelback,1,wxEXPAND|wxALL,20);
//    parentpanelback->SetSizer(vbox3);

    startgame = new wxBitmapButton(leftpanel,ID_START_GAME,wxBitmap(wxT("source\\startgame.png"),wxBITMAP_TYPE_PNG));

    wxBoxSizer *vboxleft = new wxBoxSizer(wxVERTICAL);
    vboxleft->Add(pvsai,0,wxLEFT|wxRIGHT,5);
    vboxleft->Add(aivsai,0,wxLEFT|wxRIGHT,5);
    vboxleft->Add(backtomenupanel,0,wxLEFT|wxRIGHT,5);
    vboxleft->Add(startgame,0,wxLEFT|wxRIGHT,5);
    leftpanel->SetSizer(vboxleft);

    rightpanel = new wxPanel(this,wxID_ANY,wxDefaultPosition,wxSize(700,700));
    rightpanel->SetBackgroundBitmap(*bmppvsai);

    wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL);

    hbox->Add(leftpanel,0,wxALIGN_LEFT,10);
    hbox->Add(rightpanel,1,wxRIGHT,10);

    this->SetSizer(hbox);
//    this->SetBackgroundBitmap(*bmpaivsai);

    Connect(ID_START_GAME,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(SelectGamePanel::OnClickStartGame));
    Connect(ID_PLAYER_VERSUS_AI,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(SelectGamePanel::OnClickPlayerVersusAI));
    Connect(ID_AI_VERSUS_AI,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(SelectGamePanel::OnClickAIVersusAI));
    Connect(ID_BACK_TO_MENU_PANEL,wxEVT_COMMAND_BUTTON_CLICKED,wxCommandEventHandler(SelectGamePanel::OnClickBacktoMenu));
}

void SelectGamePanel::OnClickPlayerVersusAI(wxCommandEvent&event)
{
    this->isgamesetted=true;
    this->gametype = ID_PLAYER_VERSUS_AI;
    this->rightpanel->SetBackgroundBitmap(*bmppvsai);
    wxPuts(wxT("p vs ai\n"));
    selectgamedialog = new SelectGameDialog(this,wxT("GAME SETTING"),SelectGameDialog::ID_PLAYER_VS_AI_BUTTON);
//    event.Skip();
}

void SelectGamePanel::OnClickAIVersusAI(wxCommandEvent&event)
{
    this->isgamesetted=true;
    this->gametype = ID_AI_VERSUS_AI;
    this->rightpanel->SetBackgroundBitmap(*bmpaivsai);
    wxPuts(wxT("ai vs ai\n"));
    selectgamedialog = new SelectGameDialog(this,wxT("GAME SETTING"),SelectGameDialog::ID_AI_VS_AI_BUTTON);
}

void SelectGamePanel::OnClickBacktoMenu(wxCommandEvent&event)
{
    wxPuts(wxT("back\n"));
    event.Skip();
}

void SelectGamePanel::OnClickStartGame(wxCommandEvent&event)
{
    wxPuts(wxT("masuk ke start game\n"));
    if (this->isgamesetted)
    {
        if (gametype==ID_PLAYER_VERSUS_AI)
        {
            wxPuts(selectgamedialog->nametext->GetValue());
        }

        wxPuts(wxT("STARTING GAME!!"));
    }
    else
    {

    }
    event.Skip();
}





